package cn.com.darly.videoandroidpm.ui.presenter;

import com.darly.common.ToastApp;
import com.darly.common.retrofit.FrameListener;

import java.util.List;

import cn.com.darly.videoandroidpm.bean.LoginInfo;
import cn.com.darly.videoandroidpm.ui.biz.FriendFragmentListener;
import cn.com.darly.videoandroidpm.ui.fragment.OrnamentalFlowerFragment;
import cn.com.darly.videoandroidpm.widget.shapeloading.ShapeLoadingDialog;


/**
 * @author zhangyh2 s 上午10:57:39 TODO 控制器 页面动作操作
 */
public class FriendFragmentPresenter {

    private FriendFragmentListener userBiz;
    private FriendFragmentListener.FriendFragmentInterface main;
    private ShapeLoadingDialog loading;

    public FriendFragmentPresenter(FriendFragmentListener.FriendFragmentInterface main) {
        this.main = main;
        this.userBiz = new FriendFragmentListener();
        loading = new ShapeLoadingDialog.Builder(((OrnamentalFlowerFragment)main).getActivity())
                .loadText("请求中...")
                .build();
    }

    public void friend() {
        userBiz.onStart(loading);
        main.setDisableClick();
        userBiz.onFriend(new FrameListener<List<LoginInfo>>() {
            @Override
            public void onSucces(List<LoginInfo> info) {
                userBiz.onStop(loading);
                main.setEnableClick();
                main.onSuccess(info);
            }

            @Override
            public void onFaild(int code, String info) {
                userBiz.onStop(loading);
                main.setEnableClick();
                if (code == 0){
                    ToastApp.showToast("服务端更新，请更新应用版本！");
                }else {
                    main.onFailed(info);
                }
            }
        });
    }
}